/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author adriancruz11c
 */
import ACH.mod.Snippet.Search;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.util.ArrayList;
//import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;
public class PruebasBorrar {
    
    private static JSONObject sysnsetsJSON;
    private static String synset;
    private static Object elems;
    private static List<String> synsetsWRF1;
    private static List<String> synsetsWRF2;
  public static void main(String []a) throws JSONException, UnsupportedEncodingException, IOException{
      /*double x=25.324178787878;
      DecimalFormat df = new DecimalFormat("0.00"); 
      System.out.println(df.format(x));*/

      String x="less";
      String y="harmless";
      String z=y.substring(0, y.length()-x.length());      
      System.out.println(z);
     /* String [][]x=getWordReference("http://api.wordreference.com/aca60/json/thesaurus/", "swine", "hog");
      for(String []ar:x){
          System.out.println();
          for(String y:ar)
          System.out.println(y);
      }
      String []arrWRF1=null;
      if (arrWRF1!=null){;
      }*/
      
      x="a:a";
      y="";
      String []xx=x.split(":");
      String []yy=y.split(":");
      System.out.println("TX: "+xx.length);
      System.out.println("TY: "+yy.length);
  }    
  public static String [][]getWordReference(String url,String ul1, String ul2) throws JSONException, UnsupportedEncodingException, IOException{
      synsetsWRF1 = new ArrayList< String >();
      synsetsWRF2 = new ArrayList< String >();
      String []arrWRF1=null;
      String []arrWRF2=null;
      int Nsenses1=getWordR(url, ul1, synsetsWRF1);
      int Nsenses2=getWordR(url, ul2, synsetsWRF2);
      if (Nsenses1>0 && Nsenses2>0){
        arrWRF1=new String[synsetsWRF1.size()];
        arrWRF2=new String[synsetsWRF2.size()];
        int x=0;
        for (String i:synsetsWRF1)
            arrWRF1[x++]=i;
        x=0;
        for (String i:synsetsWRF2)
            arrWRF2[x++]=i;
        System.out.println("\nsen1: " +Nsenses1+ " "+"sen2: " +Nsenses2);     
        System.out.println("a1: " +arrWRF1.length+ " "+"a2: " +arrWRF2.length);             
        double difLog=Math.abs(Math.log10(arrWRF1.length)-Math.log10(arrWRF2.length));      
     }
      String []sensesB={""+Nsenses1,""+Nsenses2};
      String [][]res= {arrWRF1, arrWRF2, sensesB};  
      return res;
      //pasar las ultimas lineas a un metodos, (depsues de las consultas)
      //se considerará las discrepacnicia entre la cantidad de senses
  }  
  public static int getWordR(String q, String ul, List<String> synsetsWR)throws JSONException, UnsupportedEncodingException, IOException{      
    //JSONObject infoHTML=Search.getJsonWordRF("http://api.wordreference.com/aca60/json/thesaurus/", "hot%20rod");                   
    JSONObject infoHTML=Search.getJsonWordRF(q, ul);        
    int i=0;
    if ((! infoHTML.has("Error")) && infoHTML.has("term0")){    
        infoHTML=(JSONObject)infoHTML.get("term0");
        infoHTML=(JSONObject)infoHTML.get("senses");
        Iterator senses = infoHTML.keys();      
        for(i=0; senses.hasNext(); i++){            
           sense(""+senses.next(),infoHTML,synsetsWR);
        }        
    }else { ;//"si no se encuentra el elemento"
     return -1;
    }
    return i;
  }
  public static void sense(String key, JSONObject senseJson, List<String> syns) throws JSONException{
        senseJson=(JSONObject)senseJson.get(key);
        senseJson=(JSONObject)senseJson.get("synonyms");   
        Iterator keys = senseJson.keys();            
        for(int i=0; keys.hasNext(); i++){
        sysnsetsJSON=(JSONObject)senseJson.get(""+keys.next());      
            boolean add = syns.add(sysnsetsJSON.getString("synonym"));
        } 
      //return syns;
  }
}
